from po.base_api import Base_Api
from tools.parseyaml import parse_yaml
from tools.sqltools import Dbmysql


class KaoYan(Base_Api):
    def kaoyan_index(self,**kwargs):
        body = {
            "method":"get",
            "url":self.host+"/zxx/v4/master",
            "params":{**kwargs}
        }
        r = self.send(body)
        return r


    def filtrate_school(self):
        data = {
            "method":"post",
            "url":self.host+'/v3/university/option'
        }
        r = self.send(data)
        all_list = []
        self.db = Dbmysql()
        area_id_list = self.db.get_data(r,'areaData','area_id')
        level_id_list = self.db.get_data(r,'levelData','level_id')
        type_id_list = self.db.get_data(r,'typeData','type_id')
        all_list.append(area_id_list)
        all_list.append(level_id_list)
        all_list.append(type_id_list)
        return all_list


    def test_school_shaixuan(self,area_id,level_id,type_id):
        body = {
            "method":"get",
            "url":self.host+"/zxx/v4/university/search",
            "params":{"area_id":area_id,"level_id":level_id,"type_id":type_id}
        }
        r = self.send(body)
        return  r

    def good_course(self):
        body = {
            "method":"get",
            "url":self.host+'/zxx/v4/master/goodcourses'
        }
        r = self.send(body)
        return  r

    def kaoyan_news_list(self,page,pagesize,userid):
        body = {
            "method":"get",
            "url":self.host+"/zxx/v4/master/news",
            "params":{
                "page":page,
                "pagesize":pagesize,
                "userid":userid
            }
        }
        r = self.send(body)
        return  r

    def kaoyan_truetopic(self,subject_id):
        body = {
            "method":"get",
            "url":self.host+'/zxx/v4/master/papers',
            "params":{
                "subject_id":subject_id
            }
        }
        r = self.send(body)
        return r

    def kaoyan_kemu(self):
        body = {
            "method":"get",
            "url":self.host + '/zxx/v4/master/subject'
        }
        r = self.send(body)
        return  r

    def get_school_subject(self):
        # 获取学校的一二级学科
        body = {
            "method": "post",
            "url": self.host + '/v2/university/u_level',
            "json":{"params":'{"school_id":"5"}'}
        }
        r = self.send(body)
        return r

    def kaoyan_find_cource(self,section,**kwargs):
        # 1 = 查课程 - 英语、2 = 查课程 - 政治、3 = 查课程 - 数学、6 = 统考专业课、7 = 按专业选课程
        body = {
            "method":"get",
            "url":self.host + '/zxx/v4/master/course',
            "params":{
                "section":section,
                **kwargs
            }
        }
        r = self.send(body)
        return  r

    def kaoyan_find_level(self,uid):
        db = Dbmysql()
        level = db.query("SELECT level_3  from zxx_user_ky  where uid = {} ".format(uid))
        return str(level[0][0])


    def kaoyan_find_school(self,uid):
        db = Dbmysql()
        school = db.query("SELECT school_id  from zxx_user_ky  where uid = {} ".format(uid))
        return str(school[0][0])



